#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct Item {
    int id;
    int value;
    int weight;
};

int main(int argc, char* argv[]) {
    // 检查是否提供了文件路径参数
    if (argc < 2) {
        cerr << "Usage: " << argv[0] << " <filepath>" << endl;
        return 1;
    }
    
    string filepath = argv[1];  // 获取文件路径参数

    int n, id, value, weight, capacity;
    cin >> n;

    vector<Item> items(n);
    for (int i = 0; i < n; ++i) {
        cin >> id >> value >> weight;
        items[i] = {id, value, weight};
    }

    cin >> capacity;

    // 创建DP表，dp[i][w]表示前i个物品在容量为w时的最大价值
    vector<vector<int>> dp(n + 1, vector<int>(capacity + 1, 0));

    // 填充DP表
    for (int i = 1; i <= n; ++i) {
        for (int w = 1; w <= capacity; ++w) {
            if (items[i-1].weight <= w) {
                // 当前物品可以放入背包，比较放入和不放入的情况
                dp[i][w] = max(dp[i-1][w], 
                              dp[i-1][w - items[i-1].weight] + items[i-1].value);
            } else {
                // 当前物品不能放入背包
                dp[i][w] = dp[i-1][w];
            }
        }
    }

    int total_value = dp[n][capacity];

    // 输出结果：filepath,total_value
    cout << filepath << "," << total_value << endl;

    return 0;
}